package thread.state;

/**
 * @author 真香
 * @create 2021-06-03 21:39
 */


/**
 *  Yield 线程礼让，重新开始回到准备执行状态,CPU重新调度，
 *   礼让不一定成功
 *
 *
 */
public class TestYield {

    public static void main(String[] args) {

        MyYield myYield = new MyYield();

        new Thread(myYield,"A").start();
        new Thread(myYield,"B").start();

    }


}


class MyYield  implements Runnable{

    @Override
    public void run() {

        System.out.println(Thread.currentThread().getName()+"线程开始执行");
        // 礼让
        Thread.yield();
        System.out.println(Thread.currentThread().getName()+"线程停止执行");


    }
}
